#include <iostream>

using namespace std;
int main()
{
	int n;
	cin >> n;
	int a = 0;
	int b = 1;
	int c = 1;
	while (c <= n)
	{
		a = b;
		b = c;
		c = a + b;
	}
	int cmpc = abs(c - n);
	int cmpb = abs(b - n);
	int res = min(cmpc, cmpb);
	cout << res << endl;
	return 0;
}